package com.example.Genericity;

import java.util.ArrayList;
import java.util.Objects;

public class Test2 {
    public static void main(String[] args) {
        //method1();

        ArrayList<Integer> list1 = new ArrayList<>();
        ArrayList<Number> list2 = new ArrayList<>();
        ArrayList<Object> list3 = new ArrayList<>();

//        printf(list1);
//        printf(list2);

//        mehtod1(list1);
        mehtod1(list2);
        mehtod1(list3);

        mehtod(list1);
        mehtod(list2);
//        mehtod(list3);

    }

    //表示传递进来集合的类型,可以是Number类型,也可以是Number让所有的父类类型
    private static void mehtod1(ArrayList<? super Number> list) {
    }

    //表示传递进来集合的类型,可以是Number类型,也可以是Number所有的子类类型
    private static void mehtod(ArrayList<? extends Number> list) {
    }

    private static void printf(ArrayList<?> list) {
    }

    private static void method1() {
        GenericityImpl1<String> genericity = new GenericityImpl1<>();
        genericity.method("abc");   //abc

        GenericityImpl2 genericity2 = new GenericityImpl2();
        genericity2.method(123);    //123
    }
}

class GenericityImpl2 implements Genericity<Integer> {

    @Override
    public void method(Integer integer) {
        System.out.println(integer);
    }
}

interface Genericity<E> {
    public abstract void method(E e);
}

class GenericityImpl1<E> implements Genericity<E> {

    @Override
    public void method(E e) {
        System.out.println(e);
    }
}